Skip to content

Fix FetchForWriting with UseIdentityMapForAggregates and strongly typed IDs#17

Merged
jeremydmiller merged 1 commit intomainfrom
fix/4214-identity-map-strong-typed-ids
Mar 29, 2026
Merged

Fix FetchForWriting with UseIdentityMapForAggregates and strongly typed IDs#17
jeremydmiller merged 1 commit intomainfrom
fix/4214-identity-map-strong-typed-ids

Conversation

@jeremydmiller
Copy link
Copy Markdown
Member

Summary

Port of JasperFx/marten#4216 (fixes JasperFx/marten#4214).

  • Fix InvalidCastException when using FetchForWriting() with UseIdentityMapForAggregates = true and aggregates that have strongly typed IDs
  • The inline projection stores the aggregate using the strong-typed key (PaymentId), but FetchForWriting accesses it using the raw stream identity type (Guid). The fix makes StoreAggregateInIdentityMap gracefully skip when the existing dictionary has an incompatible key type.

Test plan

  • 3 new regression tests (Inline single, Live single, Inline double fetch) — all passing
  • Solution compiles cleanly

🤖 Generated with Claude Code

…ates and strongly typed IDs

Port of JasperFx/marten#4216. When UseIdentityMapForAggregates is true
and the aggregate uses a strongly typed ID (e.g., PaymentId wrapping
Guid), the identity map dictionary key type mismatch caused an
InvalidCastException. The fix makes StoreAggregateInIdentityMap
gracefully skip when the existing dictionary has an incompatible key
type.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jeremydmiller jeremydmiller merged commit 27497bf into main Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FetchForWriting throws InvalidCastException when using UseIdentityMapForAggregates with strongly typed IDs

1 participant